#include<stdio.h>
//#include<conio.h>
int a[100],n,i,j,k; //global variables
void quicksort(int a[], int low, int high);
int split(int a[], int low, int high);
int main()
{
    int ch;
    printf("enter length of Array=");
    scanf("%d",&n);
    if (n==0)
	{
	printf("enter valid length!!!"); 
	}
    else
{
printf("\nlist functions using arrays");
printf("\n1. reversing array");
printf("\n2. counting number of elements in array");
printf("\n3. searching in array");
printf("\n4. sorting the array");
printf("\n5. exit\n");
printf("\nenter your choice=");
scanf("%d",&ch); 
switch (ch)
	{
case 1: rev();
	break;
case 2: count();
	break;
case 3: search();
	break;
case 4:sort();
	break;
case 5:
	break;
default: printf("enter a valid choice");
	}
}
}
int rev()
{
app();
for(i=0;i<n;i++)
{
	printf(" %d ",a[i]);
}
printf("\n reverse of array=\n ");
for(j=n;j>0;j--)
{
	printf(" %d ",a[--i]);
}
return 0;
}
int count()
{
	app();
	printf("number of elements in array= %d \n",n);
	return 0;
}

int search()
{
app();
int elem,temp=0;
printf("Enter the element to be search\n");
     scanf("%d",&elem);
for (i=0; i<n; i++)
     {
         if (a[i]==elem)
         {
           temp=1;
           printf("Element found %d , position=%d\n",elem,i);
         }
      }
       if (!temp)
     printf("Element not found\n");  
 return 0;   
}
void quicksort(int a[], int low, int high)
{
int middle;
if (low >= high) 
return;
middle = split(a, low, high);
quicksort(a, low, middle - 1);
quicksort(a, middle + 1, high);
}
int split(int a[], int low, int high)
{
int part_element = a[low];
for (;;) 
{
while (low < high && part_element <= a[high])
	high--;
	if (low >= high) break;
	a[low++] = a[high];
while (low < high && a[low] <= part_element)
	low++;
if (low >= high) 
break;
a[high--] = a[low];
}
a[high] = part_element;
return high;
}
int sort()
{
app();
quicksort(a, 0, n - 1);
printf("In sorted order: ");
for (i = 0; i < n; i++)
{
printf("%d ", a[i]);
//printf("\n");
}
return 0;
}
int app()
{
for (i = 0; i < n; i++)
{
printf("enter element=");
scanf("%d", &a[i]);
}
}

